package com.study.zouchao.superproject.myreceivedtask;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.RelativeLayout;

import com.study.zouchao.superproject.R;
import com.study.zouchao.superproject.base_zou.MyBaseFragment;
import com.study.zouchao.superproject.mypublishtask.IPublishTaskListContract;
import com.study.zouchao.superproject.mypublishtask.MyPublishPresenter;
import com.study.zouchao.superproject.util.ToastUtils;
import com.study.zouchao.superproject.util.ui.EmptyRecyclerView;
import com.study.zouchao.superproject.util.ui.OnSlideSeeMoreLisenter;

import butterknife.BindView;

/**
 * Created by Administrator on 2017/6/25.
 */

public class MyReceiveTaskFragment extends MyBaseFragment implements IReceivedTaskListContract.IReceivedTaskListView,  SwipeRefreshLayout.OnRefreshListener,  OnSlideSeeMoreLisenter.IOnSlideToBottomListener {

    @BindView(R.id.id_rv_myreceivedtask)
    EmptyRecyclerView mRvTask;
    @BindView(R.id.id_refreshing_task_list)
    SwipeRefreshLayout mRefreshing;


    @BindView(R.id.id_rl_empty_view)
    RelativeLayout mRlEmptyView;

    private View mSeeMoreloading;
    private IReceivedTaskListContract.IReceivedTaskListPresenter mPresenter;

    @Override
    protected View getLoadingTargetView() {
        return getCurrentFragmentRootView().findViewById(R.id.id_loading_my_received_task);
    }

    @Override
    protected int getFragmentLayoutID() {
        return R.layout.fragment_my_received_task;
    }


    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mPresenter = new MyReceivedPresenter(getActivity(), this);
        Log.d("replace>>>", "list");

        init();
    }
    private void init() {
        mRvTask.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL,false));
        mRvTask.setEmptyView(
                mRlEmptyView,
                false, true
        );
        mPresenter.initRecyclerView(mRvTask);
        mRefreshing.setOnRefreshListener(this);
        mRvTask.addOnScrollListener(new OnSlideSeeMoreLisenter(this));
    }

    @Override
    public void onRefresh() {
        mPresenter.onRefreshingData();
    }

    @Override
    public void showRefreshingLoading(boolean isShow) {
        if (mRefreshing != null)    mRefreshing.setRefreshing(isShow);

    }

    @Override
    public void showSeeMoreLoading(boolean isShow) {
        if (mSeeMoreloading != null) mSeeMoreloading.setVisibility(isShow ? View.VISIBLE : View.INVISIBLE);

    }



    @Override
    public void showSnackBar(String title) {
        if (mRvTask == null)    return;
        ToastUtils.showSnackbar(mRvTask, title, Snackbar.LENGTH_SHORT);

    }
    @Override
    public void setSeeMoreLoading(View footerLoadingView) {
        mSeeMoreloading = footerLoadingView;
    }

    @Override
    public void onSeeMore() {
        mPresenter.loadSeeMore();
    }
}
